#include "Logger.h"

#include "Logger.h"

void Logger::logMessage(LogLevel::Level level,
                        const char* file,
                        const char* function,
                        int line,
                        const char* format,
                        ...) {
    char header[256];
    // snprintf(header, sizeof(header), "[%s][%d][%s][%s:%s:%d]", FormatTime(), pid_, LogLevel::toString(level).c_str(),
    //  file, function, line);
    snprintf(header, sizeof(header), "[%s:%s:%d]", file, function, line);

    char message[1024];
    va_list args;
    va_start(args, format);
    vsnprintf(message, sizeof(message), format, args);
    va_end(args);

    std::cout << header << message << std::endl;
}

const char* Logger::FormatTime() {
    time_t t = time(NULL);
    struct tm* ltm = localtime(&t);
    snprintf(ret, sizeof(ret), "%d-%d-%d %d:%d:%d", ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_hour,
             ltm->tm_min, ltm->tm_sec);
    return ret;
}

Logger logger;